/*
** prompt.c for minishell2 in /home/lingla_j/work/tutorat/env
** 
** Made by julien linglain
** Login   <lingla_j@epitech.net>
** 
** Started on  Sat Mar  3 14:42:17 2012 julien linglain
** Last update Thu Mar 22 15:23:08 2012 julien linglain
*/

#include <stdlib.h>
#include "mysh.h"

void		getprompt(t_list *envi, char *user, char *host)
{
  t_node	*tmp;

  if (envi->size != 0)
    {
      tmp = envi->start;
      while (tmp != NULL)
	{
	  if (my_strcmp(tmp->key, "USERNAME") == 0)
	    user = my_strcpy(tmp->value);
	  if (my_strcmp(tmp->key, "HOST") == 0)
	    host = my_strcpy(tmp->value);
	  tmp = tmp->next;
	}
      if (user != NULL)
	my_putstr(user);
      if (host != NULL)
	{
	  if (user != NULL)
	    my_putstr("@");
	  my_putstr(host);
	}
    }
  free(user);
  free(host);
}

int	prompt(t_list *envi)
{
  char	*user;
  char	*host;

  user = NULL;
  host = NULL;
  getprompt(envi, user, host);
  my_putstr("$> ");
  free(user);
  free(host);
  return (EXIT_SUCCESS);
}
